/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package espe.ccsoft.dao;

import espe.ccsoft.models.PermisoRol;
import espe.ccsoft.orm.ORMBase;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 *
 * @author misahaelfernandez
 */
public class PermisoRolDao extends ORMBase<PermisoRol>{
    
    public final void insert (final PermisoRol permisorol) throws Exception{
        super.insertSql = "INSERT INTO PERMISOS_ROL ("
                + "PERM_ID,"
                + "ROL_ID"
                + ") VALUES(?, ?)";
        super.insert(new Object[]{
            permisorol.getPermiso_rol().getId_permiso(),
            permisorol.getPermiso_rol().getId_rol(),
            });
    }
    
    public final void update(final PermisoRol permisorol) throws Exception{
        super.updateSql = "UPDATE PERMISOS_ROL SET "
                + "ROL_ID=? "
                + "WHERE PERM_ID=?";
        super.update(new Object[]{
            permisorol.getPermiso_rol().getId_rol(),
            permisorol.getPermiso_rol().getId_permiso(),
            });
    }
    
    public final void delete(final int id_permiso) throws Exception{
        super.deleteSql = "DELETE FROM PERMISOS_ROL "
                + "WHERE PERM_ID=?";
        super.delete(new Object[]{
            id_permiso,
            });
    }
    
    public final List<PermisoRol> findByPermiso(int id_permiso) throws SQLException, Exception {
        // Sentencia SQL para realizar la consulta a la BD:
        super.findSomeSql = "SELECT * FROM PERMISOS_ROL WHERE "
                + "PERM_ID=?";
        return super.findSome(new Object[]{id_permiso,});
    }
    
    @Override
    public final List<PermisoRol> findAll() throws SQLException, Exception {
        // Sentencia SQL para realizar la consulta a la BD:
        super.findAllSql = "SELECT * FROM PERMISOS_ROL";
        return super.findAll();
    }
    
    @Override
    protected PermisoRol crearObjeto(final ResultSet rs) throws SQLException {
        PermisoRol permisorol=new PermisoRol();
        permisorol.setPermiso_rol(rs.getInt("PERM_ID"),rs.getInt("ROL_ID"));
        return permisorol;
    }
    
}
